package com.pinecone.controller;

import java.util.List;
import java.util.Map;


import org.springframework.asm.Handle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;

import com.pinecone.entity.LiveRoomViewCodeEntity;
import com.pinecone.service.LiveRoomViewCodeService;
import com.pinecone.common.utils.PageUtils;
import com.pinecone.common.utils.Query;
import com.pinecone.common.utils.R;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.mvc.Controller;


/**
 * 直播间观看码
 * 
 * @author hushangjie
 * @email 979783618@qq.com
 * @date 2017-10-24 11:52:29
 */
@RestController
@RequestMapping("live_room_view_code")
public class LiveRoomViewCodeController {
	@Autowired
	private LiveRoomViewCodeService liveRoomViewCodeService;
	/**
	 * 列表
	 */
	@GetMapping("")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		if (params.get("page") != null && params.get("limit")!= null){
			List<LiveRoomViewCodeEntity> liveRoomViewCodeList = liveRoomViewCodeService.queryList(query);
			int total = liveRoomViewCodeService.queryTotal(query);
			
			PageUtils pageUtil = new PageUtils(liveRoomViewCodeList, total, query.getLimit(), query.getPage());
			
			return R.ok().put("page", pageUtil);
		}else{
			List<LiveRoomViewCodeEntity> liveRoomViewCodeList = liveRoomViewCodeService.queryList(query);
			return R.ok().put("list", liveRoomViewCodeList);
		}
		
	}
	@GetMapping("/code/{room_id}")
    public R getViewCode(@PathVariable("room_id") String liveRoomId){
        LiveRoomViewCodeEntity liveRoomViewCodeEntity = liveRoomViewCodeService.queryByRoomId(liveRoomId);
        return R.ok().put("liveRoomViewCode", liveRoomViewCodeEntity);
    }
	
	/**
	 * 信息
	 */
	@GetMapping("/{liveRoomCodeId}")
	public R info(@PathVariable("liveRoomCodeId") Integer liveRoomCodeId){
		LiveRoomViewCodeEntity liveRoomViewCode = liveRoomViewCodeService.queryObject(liveRoomCodeId);
		
		return R.ok().put("liveRoomViewCode", liveRoomViewCode);
	}
	
	/**
	 * 保存
	 */
	@PostMapping("")
	public R save(@RequestBody LiveRoomViewCodeEntity liveRoomViewCode){
		liveRoomViewCodeService.save(liveRoomViewCode);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@PutMapping("")
	public R update(@RequestBody LiveRoomViewCodeEntity liveRoomViewCode){
		liveRoomViewCodeService.update(liveRoomViewCode);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@DeleteMapping("/{id}")
	public R delete(@PathVariable(value = "id",required = true) int h5AdPageId){
		liveRoomViewCodeService.delete(h5AdPageId);
		
		return R.ok();
	}
	
}
